# import cv2
# import numpy as np
# img = np.zeros((240, 320), dtype=np.uint8)
# n = 0
# while True:
#     cv2.imshow("grayscale_test", img)
#     img[:,:] = n
#     n += 20
#     print(img[1,1])
#     key = cv2.waitKey(1000)
#     if key == 27:
#         break
# cv2.destroyWindow("grayscale_test")

# def swap(a, b, c):
#     return b,c,a
#
# import cv2
# import numpy as np
# img = np.zeros((240, 320, 3), dtype=np.uint8)
# a,b,c = 0,1,2
# while True:
#     img[:80, :, a] = 255
#     img[80:160, :, b] = 255
#     img[160:240, :, c] = 255
#     cv2.imshow("color_test", img)
#     key = cv2.waitKey(1000)
#     img[:,:,:] = 0
#     a, b, c = swap(a, b, c)
#     if key == 27:
#         break
# cv2.destroyWindow("color_test")

# import cv2
#
# # 1. 读取原图并显示
# img = cv2.imread("images/008.jpg")
# cv2.imshow("original_image", img)
# if cv2.waitKey(10000) == 27:
#     cv2.destroyWindow("original_image")
#
# # 2. 分离通道
# b = img[:, :, 0]  # Blue 通道
# g = img[:, :, 1]  # Green 通道
# r = img[:, :, 2]  # Red 通道
#
# # 3. 分别显示 B、G、R 通道，并等待 ESC 关闭
# pic_list = [("b_channel", b), ("g_channel", g), ("r_channel", r)]
# for name, channel in pic_list:
#     cv2.imshow(name, channel)
#     if cv2.waitKey(10000) == 27:
#         cv2.destroyWindow(name)

# import cv2
#
# # 1. 读取原图并显示
# img = cv2.imread("images/008.jpg")
# cv2.imshow("original_image", img)
# if cv2.waitKey(10000) == 27:
#     cv2.destroyWindow("original_image")
#
# # 2. 分离通道
# b, g, r = cv2.split(img)
#
# # 3. 分别显示 B、G、R 通道，并等待 ESC 关闭
# pic_list = [("b_channel", b), ("g_channel", g), ("r_channel", r)]
# for name, channel in pic_list:
#     cv2.imshow(name, channel)
#     if cv2.waitKey(10000) == 27:
#         cv2.destroyWindow(name)

import cv2

# 1. 读取原图并显示
img = cv2.imread("images/008.jpg")
cv2.imshow("original_image", img)
if cv2.waitKey(10000) == 27:
    cv2.destroyWindow("original_image")

# 2. 分离通道
b, g, r = cv2.split(img)
rgb = cv2.merge([b,g,r])
gbr = cv2.merge([g,b,r])

# 3. 分别显示 B、G、R 通道，并等待 ESC 关闭
pic_list = [("rgb_channel", rgb), ("gbr_channel", gbr)]
for name, channel in pic_list:
    cv2.imshow(name, channel)
    if cv2.waitKey(10000) == 27:
        cv2.destroyWindow(name)